﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using Dataglot;

namespace IrishSettings
{
    public class SettingsForUserController : TableController<GenericSettingStored>
    {
        public SettingsForUserController(DataFactory factory, DbConnection connection, DbTransaction transaction)
            : base(factory,connection, transaction)
        {
            if(connection==null)
                throw new ArgumentException("connection parameter required, can't be null");
            tableName = "{$ns}_settings_user";

            sharedConnection = connection;
            columns = new Dictionary<string,DbType>
                          { 
                              {"id",DbType.Int32},
                              {"user_name",DbType.String},
                              {"name",DbType.String},
                              {"serialized_value",DbType.String},
                              {"version",DbType.String},
                              {"scope",DbType.String},
                              {"application",DbType.String},
                              {"value_type",DbType.String},
                              {"culture",DbType.String},
                          };
        }

        public override GenericSettingStored Select(long id)
        {
            return ProcessSelect(id);
        }

        public override List<GenericSettingStored> SelectList(int from, int to)
        {
            return ProcessSelectList(from, to);
        }

        public override GenericSettingStored Insert(GenericSettingStored setting)
        {
            return ProcessInsert(setting);
        }

        public override GenericSettingStored Update(GenericSettingStored setting)
        {
            return ProcessUpdate(setting);   
        }

        public override void Delete(long id)
        {
            ProcessDelete(id);
        }

        public override bool Exists(long id)
        {
            return ProcessExists(id);
        }
    }
}
